package com.config.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.config.dao.EquMoldDao;
import com.config.dao.EquipmentDao;
import com.config.entity.Equipment;

@Service(value="equipmentService")
public class EquipmentServiceImpl implements EquipmentService{

	@Resource(name = "equipmentDao")
	private EquipmentDao equipmentDao;
	@Resource(name = "equMoldDao")
	private EquMoldDao moldDao;
	
	@Override
	public void save(Equipment entity) {
		equipmentDao.save(entity);
	}

	@Override
	public void delete(int id) {
		equipmentDao.delete(id);
	}

	@Override
	public void update(Equipment entity) {
		equipmentDao.update(entity);
	}

	@Override
	public Equipment getEquipment(int id) {
		return equipmentDao.get(id);
	}
	
	@Override
	public List<Equipment> listByLine(Integer lineId) {
		return equipmentDao.listByLine(lineId);
	}

	@Override
	public List<Equipment> findByLine(Integer lineId,int start, int limit) {
		List<Equipment> list=equipmentDao.findByLine(lineId, start, limit);
		for(Equipment e:list){
			e.setType(moldDao.get(e.getEquMoldId()).getEquType());
		}
		return list;
	}
	
	@Override
	public int countByLine(Integer lineId) {
		return equipmentDao.countByLine(lineId);
	}

	@Override
	public List<Equipment> findByEquModlId(int equMoldId) {
		return equipmentDao.findByEquModlId(equMoldId);
	}

	@Override
	public Equipment getByEquNo(String equNo) {
		return equipmentDao.getByEquNo(equNo);
	}
	/**
	 * 查询所有采集能耗数据的设备
	 * @return
	 */
	public Map<String,Object> getAllEquipment(){
		Map<String,Object> equComboBox=new HashMap<String,Object>();
		List<Map<String,String>> list=new ArrayList<Map<String,String>>();
		List<Equipment>equs=equipmentDao.getAllEquipment();
		if(equs.size()!=0){
			for(Equipment e:equs){
				Map<String,String> emap=new HashMap<String,String>();
				emap.put("label", e.getEquNo());
				emap.put("value", e.getId().toString());
				list.add(emap);
			}
		}
		equComboBox.put("equComboBox", list);
		return equComboBox;
	}
}
